package main

import (
	"fmt"
	"jvm/classpath"
	"jvm/rtda/heap"
	"strings"
)

func main() {
	cmd := parseCmd()
	if cmd.versionFlag {
		fmt.Println("version 0.0.1")
	} else if cmd.helpFlag || cmd.class == "" {
		printUsage()
	} else {
		startJVM(cmd)
	}

}
func startJVM(cmd *Cmd) {
	classpath := classpath.NewClassPath(cmd.XjreOption, cmd.cpOption)
	loader := heap.NewClassLoader(classpath)
	className := strings.Replace(cmd.class, ".", "/", -1)
	class := loader.LoadClass(className)
	mainMethod := getMainMethodclass(class)
	interpret(mainMethod)
}
func getMainMethodclass(class *heap.Class) *heap.Method {
	for _, method := range class.Methods() {
		if method.Name() == "main" {
			return &method
		}
	}
	return nil
}
